<?php
namespace app\shops\controller;

use think\Db;
header("Content-type:text/html;charset=utf-8");

class Index extends Base
{
    /**
     * 后台首页
     * @return [type] [description]
     */
    public function index()
    {

        //拿到全部营销方案
        $all_list = Db('appreciate')->select();
        foreach ($all_list as $k => $v) {
            $all_list[$k]['sub_menu'] = json_decode($v['sub_menu'], true);
        }

        //拿到当前店铺全部营销方案
        $list = Db('appreciate_user')->where('shop_id',$this->shop_id)->where('status',0)->select();
        //是否到期
        foreach ($list as $k=>$v){
            if (time()>$v['expiration_time']){
                Db('appreciate_user')->where('shop_id',$this->shop_id)->where('id',$v['id'])->update(['status'=>1]);
            }
        }
        $list = Db('appreciate_user')->where('shop_id',$this->shop_id)->where('status',0)->select();
        $this->assign('all_list',$all_list);
        $this->assign('list',$list);
        return $this->fetch();
    }


    /**
     * 控制台
     */
    public function welcome()
    {
        return $this->fetch();
    }

}
